package com.quwan.manager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.quwan.entity.TScaleSetting;
import com.quwan.entity.TSystemPay;
import com.quwan.manager.service.SystemService;
import com.quwan.mapper.TScaleSettingMapper;
import com.quwan.mapper.TSystemPayMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author quan
 * @date 2021-10-25 15:26
 */

@Service
@RequiredArgsConstructor
public class SystemServiceImpl implements SystemService {
    private final TSystemPayMapper systemPayMapper;
    private final TScaleSettingMapper scaleSettingMapper;

    // @Cacheable(cacheNames = CacheKey.DATA.payPower)
    @Override
    public List<TSystemPay> getPayPowerList() {
        return systemPayMapper.selectList(new QueryWrapper<>(null));
    }

    // @CacheEvict(cacheNames = CacheKey.DATA.payPower,allEntries = true,beforeInvocation = true)
    @Override
    public void changePayPowerStatus(String id, String status) {
        int row = systemPayMapper.updateById(
                new TSystemPay()
                        .setId(Long.parseLong(id))
                        .setStatus(Integer.parseInt(status)));

    }

    @Override
    public boolean updPayPower(String id, String name) {
        return systemPayMapper.updateById(new TSystemPay().setId(Long.parseLong(id)).setName(name))==1;
    }

    @Override
    public boolean addPayPower(TSystemPay systemPay) {
       return systemPayMapper.insert(systemPay)==1;
    }

    @Override
    public List<TScaleSetting> getSpreadList() {
        return scaleSettingMapper.selectList(null);
    }

    @Override
    public boolean updateScale(String id , BigDecimal scale) {
        if (scale==null||BigDecimal.ZERO.compareTo(scale)==0)
            return false;
        return scaleSettingMapper.update(null,new LambdaUpdateWrapper<TScaleSetting>().set(TScaleSetting::getScale,scale).eq(TScaleSetting::getId,id))==1;
    }

}
